package cn.shengchao.rule.condition;

import cn.shengchao.rule.condition.matchType.IMatchType;
import cn.shengchao.rule.condition.paramKey.IConditionParamKey;
import cn.shengchao.rule.condition.valueType.IValueType;
import cn.shengchao.rule.engine.RuleElementContainer;
import lombok.Data;

import java.util.Map;

/**
 * @program: examstarapi
 * @description: 条件接口
 * @author: Xiong weiqiang
 * @create: 2025-04-11 14:20
 */
@Data
public abstract class ICondition {
    /**
     * 条件参数的定义
     */
    private IConditionParamKey parameterKey;
    /**
     * 条件需要的映射值
     */
    private String matchValue;
    /**
     * 条件的匹配方式
     */
    private String matchTypeKey;
    /**
     * 条件的值类型
     */
    private String valueTypeKey;
    /**
     * 条件的优先级
     */
    private int priority;

    public abstract boolean isMatch(Map<String,String> targetValueMap);

    protected boolean isMatch(String targetValue,String matchValue){
        IMatchType matchType= RuleElementContainer.getMatchType(getMatchTypeKey());
        IValueType valueType= RuleElementContainer.getValueType(getValueTypeKey());
        return matchType.isMatch(targetValue,matchValue,valueType);
    }
}